import { saveSmsSetting, selSmsSetting, selSmsCheck } from '@/services/smsSetting';
import { errNotification, successNotification } from '@/utils/notification';

export default {
    namespace: 'smsSetting',
  
    state: {
        setSmsSettingList: [],
        isSmsCheck: false
    },
  
    effects: {
      *fetchSaveSmsSetting(param, { call, put }) { //保存设置
        const response = yield call(saveSmsSetting, param);
        if(response.success){
            successNotification("设置成功","")
        }else{
            errNotification("设置失败",response.subMsg)
        }
        const response2 = yield call(selSmsSetting, param);
        if(response2.success){
            yield put({
                type: 'setSmsSettings',
                payload: response2.data,
            });
        }
      },
      *fetchSelSmsSetting(param, { call, put }) { //查询配置
        const response = yield call(selSmsSetting, param);
        if(response.success){
            yield put({
                type: 'setSmsSettings',
                payload: response.data,
            });
        }
      },
      *fetchSelSmsCheck(param, { call, put }) { //查询配置
        const response = yield call(selSmsCheck, param);
        if(response.success){
            yield put({
                type: 'setIsSmsCheck',
                payload: response.data.isSmsCheck,
            });
        }
      },
    },
  
    reducers: {
      setSmsSettings(state, action) {
        return {
            ...state,
            setSmsSettingList: action.payload,
        };
      },
      setIsSmsCheck(state, action) {
        return {
            ...state,
            isSmsCheck: action.payload,
        };
      },
    },
  };